import { defineStore } from 'pinia';
import * as systemApi from '@/api/system';
import { Message } from '@arco-design/web-vue';

const useMenuStore = defineStore('menu', () => {
    async function getMenus(param?: any) {
        const response: any = await systemApi.queryMenuList(param)
        if (response.code === 20000) {
            return response.data.menus
        }
        return []
    }

    async function deleteMenu(param: { id?: number }) {
        const response: any = await systemApi.deleteMenu(param)
        if (response.code === 20000) {
            Message.success('移除成功');
        }
    }

    async function saveMenu(param: any) {
        if (param.id) {
            await systemApi.updateMenu(param);
        } else {
            await systemApi.createMenu(param);
        }
        Message.success('保存成功');
    }

    return { getMenus, deleteMenu, saveMenu }
});

export default useMenuStore;
